def cute(y):
    t = True
    for z in range(2, int(y ** 0.5)+1):
        if y % z == 0:
            t = False
            break
    return t





m = int(input())
if m < 1000 or m > 9999:
    print(0)
else:
    darl = str(m)
    tu = 0
    for a in range (len(darl)):
        for e in range(a+1, len(darl)+1):
            erl = int(darl[a:e])
            if cute(erl):
                tu = max(tu, erl)
    print(tu)

